package com.happyass.show.controller;

import com.happyass.service.ExcelService;
import com.happyass.show.entity.Activity;
import com.happyass.show.entity.Addr;
import com.happyass.show.service.ActivityService;
import com.happyass.show.service.AddrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Set;

/**
 * TODO
 *
 * @author admin
 * @date 2021/1/5 16:50
 *
 * <P></P>
 **/

@Controller
@RequestMapping("/activity")
public class ActivityController {

    @Autowired
    ActivityService activityService;
    @Autowired(required = false)
    AddrService addrService;
    @Autowired
    ExcelService excelService;


    //后台表演节目表显示
    @RequestMapping("/activityList")
    public String list(Model map, Activity activity){
        HashMap<String, Object> hm = activityService.activityList(activity);
        map.addAttribute("list",hm);
        return "show/activity/activityIndex";
    }

    //停用启用
    @RequestMapping("/activityStatus")
    @ResponseBody
    public HashMap<String,Object> status(Activity activity, Integer activityStatus){

        return activityService.acivityStatus(activity.getActivityId(),activityStatus);
    }


    //后台表演节目新增界面跳转
    @RequestMapping("/activity")
    public String add(Model map){
        map.addAttribute("addrList",addrService.findAll());
        return "show/activity/activityAdd";
    }

    //后台表演节目新增数据交互
    @RequestMapping("/add")
    @ResponseBody
    public HashMap<String, Object> add(Activity activity){
        HashMap<String, Object> map = activityService.activityAdd(activity);
        return map;
    }

    //后台表演节目新增 节目所在具体地址 下拉框内容显示
    @RequestMapping("/area")
    @ResponseBody
    public Set<String> area(String activityAddr){
        return activityService.activityArea(activityAddr);
    }

    //后台表演节目删除
    @RequestMapping("/del")
    @ResponseBody
    public HashMap<String, Object> del(Integer activityId){
        HashMap<String, Object> map = activityService.activityDel(activityId);
        return map;
    }

    //后台表演节目批量删除
    @RequestMapping("/delMany")
    @ResponseBody
    public HashMap<String, Object> del(String ids){
        HashMap<String, Object> map = activityService.activitysDel(ids);
        return map;
    }

    //后台表演节目修改页面跳转
    @RequestMapping("/update")
    public String update(Model map,Integer activityId){
        List<Addr> addrList = addrService.findExceptActivityAddr(activityId);
        Set<String> areaList = activityService.findExceptActivityArea(activityId);
        map.addAttribute("act",activityService.update(activityId));
        map.addAttribute("addrList",addrList);
        map.addAttribute("areaList",areaList);
        return "show/activity/activityUpdate";
    }

    //后台表演节目修改
    @RequestMapping("/updateActivity")
    @ResponseBody
    public HashMap<String, Object> update(Activity activity){
        return activityService.activityUpdate(activity);
    }


    //后台表演节目搜索
    @RequestMapping("/activitySearch")
    public String search(Model map,String searchKey,String searchValue,Activity activity){
        HashMap<String, Object> hm = activityService.activitySearch(searchKey, searchValue, activity);
        map.addAttribute("list",hm);
        if (hm.get("back")!=null){
            return "show/activity/activityIndex";
        }else {
            return "show/activity/activitySearch";
        }
    }


    //后台表演节目excel导出
    @RequestMapping("/activityExcel")
    public void excel(HttpServletResponse response,String searchKey,String searchValue) {
        excelService.activityExcel(response,searchKey,searchValue);
    }

    //后台表演节目 回收站
    @RequestMapping("/retrieve")
    public String retrieve(Model map,Activity activity){
        map.addAttribute("list",activityService.findRetrieve(activity));
        return "show/activity/activityRetrieve";
    }

    //后台表演节目恢复
    @RequestMapping("/resume")
    @ResponseBody
    public HashMap<String, Object> resume(Integer activityId){
        HashMap<String, Object> map = activityService.activityRes(activityId);
        return map;
    }

    //后台表演节目批量恢复
    @RequestMapping("/resumeMany")
    @ResponseBody
    public HashMap<String, Object> resume(String ids){
        HashMap<String, Object> map = activityService.activitysRes(ids);
        return map;
    }

    //后台表演节目搜索
    @RequestMapping("/retrieveSearch")
    public String retrieveSearch(Model map,String searchKey,String searchValue,Activity activity){
        HashMap<String, Object> hm = activityService.retrieveSearch(searchKey, searchValue, activity);
        map.addAttribute("list",hm);
        if (hm.get("back")!=null){
            return "show/activity/activityRetrieve";
        }else {
            return "show/activity/activityRetrieveSearch";
        }
    }
}
